$.fn.extend({
	//鼠标滑入显示,滑出隐藏
	changeStyle:function(obj,style){
		$(obj).css({
			display:style
		});
	},

function() ajaxFun(type,url,isAsyn,data,callBack){
			//1.建立XML对象
			let xhr;
			if (window.ActiveXObject) {
				//ie
				xhr = new ActiveXObject("Microsoft.XMLHttp");
			} else {
				//非ie
				xhr = new XMLHttpRequest();
			}
			type=type.toLowerCase();
			if(type=="get"){
				if(data!=""){
					url+="?"+data;
				}
				xhr.open(type,url,isAsyn);
				xhr.send();
			}else if(type=="post"){
				xhr.open(type,url,isAsyn);
				xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xhr.send(data);
			}else{
				console.log("输入有误");
			}
			//4.等待
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4&&xhr.status==200){
					callBack(xhr.responseText);
				}
			}
		}
	
 // function getAjax(typeId){
	// 	$.get("goodsAndShoppingCart/getGoodsList.php",`typeId=${typeId}`,function(data){
	// 		let goodsList=JSON.parse(data);
	// 		let htmlStr="";
	// 		for(let i=0;i<goodsList.length;i++){
	// 			htmlStr+=`
	// 				<li class="goods-list" onclick=location.href="detailsPage.html?goodsId=${goodsList[i].goodsId}">
	// 					<img src="${goodsList[i].goodsImg}">
	// 					<h5>名称：${goodsList[i].goodsName}</h5>
	// 					<b>价格：¥${goodsList[i].goodsPrice}</b>
	// 					<p>描述：${goodsList[i].goodsDesc}</p>
	// 				</li>
	// 			`
	// 		}
	// 		$("#box").html(htmlStr);
	// 		$(".goods-number").html(goodsList.length);
	// 	});
	// }
	
//1.setCookie设置/改cookie
	function setCookie(key,value,day){
		if(day!=undefined){
			let date =new Date();
			date.setDate(date.getDate()+Number(day));
			document.cookie=`${key}=${value};expires=`+date;
		}else{
			document.cookie=`${key}=${value}`;
		}
	}
//2.getCookie获取cookie
	function getCookie(key){
		let strCookie=document.cookie;
		let arrCookie=strCookie.split("; ");
		for(let i=0;i<arrCookie.length;i++){
			let item=arrCookie[i].split("=");
			if(item[0]==key){
				return item[1];
			}
		}
		return "";
	}	
//3.delCookie删除cookie
	function delCookie(key){
		setCookie(key,'',-1);
	}	
		
	
	function loginAndregister(){
		let cookie=getCookie("username");
		if(cookie!=""){
			$(".login").html("已登录");
			$(".register").html("已注册");
			$(".my-cart").click(function(){
				location.href="cart.html";
			});
		}else{
			$(".my-cart").click(function(){
				location.href="login.html";
			});
			$(".login").click(function(){
				location.href="login.html";
			});
			$(".register").click(function(){
				location.href="register.html"
			})
		};
	}
	